package com.wealth.scsj.b_app.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.wealth.scsj.b_app.R;
import com.wealth.scsj.b_app.bean.ShopChooseListBean;

import java.util.List;

/**
 * 当前账号页面 店铺切换adapter
 */
public class ChooseShopListAdapter extends RecyclerView.Adapter<ChooseShopListAdapter.MyViewHolder> {

    private Context mContext;
    private List<ShopChooseListBean> mList;
    private LayoutInflater mInflater;
    SwitchOnClick switchOnClick;

    public ChooseShopListAdapter(Context context, List<ShopChooseListBean> data) {
        this.mContext = context;
        this.mList = data;
        mInflater = LayoutInflater.from(context);
    }

    public void setSwitchOnClick(SwitchOnClick switchOnClick) {
        this.switchOnClick = switchOnClick;
    }
    @Override
    public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = mInflater.inflate(R.layout.item_choose_shop_list, parent, false);
        MyViewHolder viewHolder = new MyViewHolder(view);
        return viewHolder;
    }

    @Override
    public void onBindViewHolder(MyViewHolder holder, final int position) {

        holder.mShopNameTv.setText(mList.get(position).getShop_name());
        holder.mShopAddressTv.setText(mList.get(position).getShop_address());

        holder.mShopSwitchTv.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                switchOnClick.onclick(position);
            }
        });
    }

    @Override
    public int getItemCount() {
        return mList.size();
    }

    public class MyViewHolder extends RecyclerView.ViewHolder {

        public TextView mShopNameTv;
        public TextView mShopSwitchTv;
        public TextView mShopAddressTv;
        public ImageView mShopLogoIv;


        public MyViewHolder(View itemView) {
            super(itemView);
            mShopNameTv =  itemView.findViewById(R.id.shop_name_tv);
            mShopSwitchTv =  itemView.findViewById(R.id.shop_switch_tv);
            mShopLogoIv =itemView.findViewById(R.id.shop_logo_iv);
            mShopAddressTv =itemView.findViewById(R.id.shop_address_tv);
        }
    }

    public interface SwitchOnClick{
        void onclick(int position);
    }
}
